package com.mgr.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;

import org.hibernate.mapping.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.mgr.model.Accounts;
import com.mgr.model.Customers;
import com.mgr.service.AccountService;
import com.mgr.service.CustomerService;

@Controller
public class ViewAccountController {
	@Autowired
	private AccountService accountService;
	@Autowired
	private CustomerService customerService;

	@RequestMapping("view_Account")
	public String viewAccountProfile(HttpSession session,
			java.util.Map<String, Object> map, HttpServletRequest resq) {
		String result = "viewAccountProfile.tile";
		String user = (String) session.getAttribute("user");
		if (user == null || user == "") {
			result = "login";
		} else {
			Customers customer = customerService.getCustomers(Integer
					.parseInt(user));
			map.put("cust", customer);
			String accId = resq.getParameter("account");
			Accounts acc = accountService.getAccount(Integer.parseInt(accId));
			if (accId != null && !accId.isEmpty()) {
				map.put("acct", acc);
			}
		}

		return result;
	}

	
	

}
